package com.mm.cloud.common.mq.enums;

import com.mm.cloud.common.mq.constant.QueueConstants;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * 队列枚举
 *
 * @author mr
 * @since 2021-06-30
 */
@Getter
@AllArgsConstructor
public enum QueueEnum {

    SYSTEM_LOG_QUEUE("systemLogQueue", QueueConstants.SYSTEM_LOG_QUEUE, RoutingKeyEnum.SYSTEM_LOG_ROUTING),
    SEND_SMS_QUEUE("smsQueue", QueueConstants.SMS_QUEUE, RoutingKeyEnum.SMS_ROUTING),
    WS_QUEUE("wsQueue", QueueConstants.WS_QUEUE, RoutingKeyEnum.WS_ROUTING);

    /**
     * spring 容器 bean 名称
     */
    private String name;
    /**
     * 队列 key
     */
    private String key;
    /**
     * 路由枚举
     */
    private RoutingKeyEnum routing;

    private static final Map<String, QueueEnum> QUEUES = new HashMap<>();

    static {
        EnumSet<QueueEnum> queues = EnumSet.allOf(QueueEnum.class);
        for (QueueEnum queue : queues) {
            QUEUES.put(queue.getKey(), queue);
        }
    }

    /**
     * 得到队列枚举
     *
     * @param key
     * @return
     */
    public static QueueEnum of(String key) {
        return QUEUES.get(key);
    }
}
